package learnScala

object CountTemperature {
    def main(args: Array[String]): Unit = {

        val lst1 = scala.io.Source.fromFile("D:/project/KafkaSparkStreaming/src/main/resources/temperature.txt").getLines.toList
        val lst2 = lst1.map(s=>(s.split(" ")(0).toInt,s.split(" ")(1).toInt))
        val lst3 = lst2.groupBy(_._1).mapValues(_.map(_._2).max).toList.sortBy(_._1)
        //求最大值、最小值、平均值

        lst2.groupBy(_._1).mapValues(l=>((l.map(_._2).max),l.map(_._2).min,l.map(_._2).sum*1.0/l.size)).toList.sortBy(_._1).foreach(println)
        //年份升序、温度降序

        lst2.sortWith((a,b) => {if(a._1 == b._1)a._2 > b._2 else a._1 < b._1}).foreach(println)
    }

}
